<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>File Upload</title>
<%@ page isELIgnored="false"%>
<%@ page import="nc.vo.sm.UserVO"%>
<%@ page import="nc.vo.ebvp.logindex.pojo.Constant"%>
<%@ page import="nc.bs.ebvp.sourcingcoll.Constants"%>
<%@ page import="nc.bs.ebvppub.ebvpservicefactory.LoadConfigProperty"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
	String path = request.getContextPath();
	String strSessionId = request.getSession().getId();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path ;
	if(basePath.endsWith("/")){
		basePath = basePath.substring(0,basePath.length()-1);
	}
	String strParaEc021 = (String) request.getSession().getAttribute(
			Constants.ID_EC021);
	UserVO userVo = (UserVO) request.getSession().getAttribute(
			Constant.USER_INFO);
	boolean isClientCa = false;
	
	if (userVo != null) {
		//供应商客户端是否支持CA
		if ("Y".equals(strParaEc021)
				|| "y".equals(strParaEc021)
				|| (null != userVo.getIsca() && userVo.getIsca()
						.booleanValue())) {
			isClientCa = true;
		}
	} else {
		isClientCa = false;
	}
	//CA厂商名称
	String strCaFactory = (String) request.getSession().getAttribute(
			LoadConfigProperty.EBVP_CA_FACTORY);
	//获取服务器IP和端口
	String strServerName = request.getServerName();
	int intServerPort = request.getServerPort();
	String header_logo = "header_logo";
	String strSelLan = (String)request.getParameter("sel_lan");
	if(null == strSelLan){
		strSelLan = (String)request.getSession().getAttribute("sel_lan");
	}
	String strFileUploadLang = "zh-cn.js";
	if("english".equals(strSelLan)){
		strFileUploadLang = null;
	}else if("tradchn".equals(strSelLan)){
		strFileUploadLang = "tr-cn.js";
	}else if("french".equals(strSelLan)){
		strFileUploadLang = "fr.js";
	}else if("german".equals(strSelLan)){
		strFileUploadLang = "de.js";
	}
%>

<%
	if (isClientCa) {
%>
	<%
		if (Constants.CA_FACTORY_ITRUS.equals(strCaFactory)) {
	%>
		<script type="text/javascript" src="../js/itrusforNC.js"></script>
		<script type="text/javascript" src="../js/pta.js"></script>
	<%
		} else if (Constants.CA_FACTORY_INFOSEC.equals(strCaFactory)) {
	%>
		<script type="text/javascript" src="../js/Infosec4NC.js"></script>
	<%
		} else if (Constants.CA_FACTORY_DEAN.equals(strCaFactory)) {
	%>
		<script type="text/javascript" src="../js/DatechJs.js"></script>
	<%
		}
	%>
<%
	}
%>
<%
	String url = request.getRequestURL().toString();
	String urls[] = url.split("/ebvp/");
	String uploadMode = request.getParameter("uploadMode");
	String userCode = request.getParameter("userCode");
	String pkReleaseFileB = request.getParameter("pkReleaseFileB");
	String pkSupcheckH = request.getParameter("pkSupcheckH");
	String isNeedAddRow = request.getParameter("isNeedAddRow");
	String comflag = request.getParameter("comflag");
	String id = request.getParameter("id");
	String type = request.getParameter("type");
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="<%=basePath%>/"></base>
<style type="text/css">
	body {
		font-family:Verdana, Geneva, sans-serif;
		font-size:13px;
		color:#333;
	}
</style>
<link rel="stylesheet" href="commonres/common/frame/src/js/upload/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" />
<script type="text/javascript" src="commonres/base/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/plupload.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/plupload.gears.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/plupload.silverlight.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/plupload.flash.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/plupload.browserplus.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/plupload.html4.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/plupload.html5.js"></script>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<% 
	if(null != strFileUploadLang){
%>
<script type="text/javascript" src="commonres/common/frame/src/js/upload/i18n/<%=strFileUploadLang%>"></script>
<%
	}
%>
</head>
<body style="overflow: hidden" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">
<form method="post">
	<div style="float: left; margin-right: 0px;margin-left: 0px">
		<div id="uploader" style="width: 600px; height: 310px;">You browser doesn't have flash,html5,silverlight,html4 support.</div>
	</div>
	<br style="clear: both" />
</form>
<script type="text/javascript">
function getParamsurl(name) {
    var pos, str, para, parastr;
    var array = []
    str = window.location.href;
    if (str.split("?")[1] != undefined && str.split("=")[1] != undefined) {
      parastr = str.split("?")[1];
      parastr=decodeURIComponent(parastr);
      console.log(parastr);
      var arr = []
      arr = parastr.split("&");
      
      for (var i = 0; i < arr.length; i++) {
        array[arr[i].split("=")[0]] = arr[i].split("=")[1];
      }
 
    }
    //alert(array["projectId"]);
    return array[name];//project为所要获取的参数
 
  }

$(function() {
	// Setup html4 version
	var filters = [{ title : "Image files", extensions : "jpg,jpeg,bmp,png" },
			{ title : "Word files", extensions : "doc,docx" },
			{ title : "PDF files", extensions : "pdf" }];
	var max_file_size = '20mb';
	var ispic =  getParamsurl("ispic")
	if(ispic && ispic == 'Y'){
		filters = [{title:"允许文件类型",extensions:"jpg,png"}];
		max_file_size = '500kb';
	}
	
	
	$("#uploader").pluploadQueue({
		// General settings
		runtimes : 'html4,flash,silverlight',
		url : '<%=urls[0]%>/ebvp/ebvpfile/upload',
		max_file_size:max_file_size,
		filters:filters,
		unique_names : true,
		multiple_queues:true,
		// Flash settings
		flash_swf_url : '<%=basePath%>/commonres/common/frame/src/js/upload/plupload.flash.swf',
		// Silverlight settings
		silverlight_xap_url : '<%=basePath%>/commonres/common/frame/src/js/upload/plupload.silverlight.xap',
		// PreInit events, bound before any internal events
		preinit: {
			Init: function(up, info) {
				
			},
			UploadFile: function(up, file) {
				// You can override settings before the file is uploaded
				 up.settings.url = '<%=urls[0]%>/ebvp/ebvpfile/upload';
				 up.settings.url += '?upload_mode='+<%=uploadMode%>;
				 up.settings.url +='&upload_file_size='+file.size;
				 up.settings.url +='&upload_pk_release_file_b='+'<%=pkReleaseFileB%>';
				 up.settings.url +='&upload_pk_supinfocheck_h='+'<%=pkSupcheckH%>';
				 up.settings.url +='&upload_id='+'<%=id%>';
				 up.settings.url +='&upload_type='+'<%=type%>';
				 up.settings.url +='&upload_file_name='+escape(encodeURIComponent(file.name));
				 <%if (isClientCa && type == null) {%>
				 	var sn = getSN('<%=userCode%>');
					var signature = encodeURIComponent(getSignMsg(file.fullpath));
					up.settings.url +='&upload_signature='+signature;
					up.settings.url +='&upload_sn='+sn;
				 <%}%>
				 
			}
		},

		// Post init events, bound after the internal events
		init: {
			Refresh: function(up) {
			},

			StateChanged: function(up) {
			},

			QueueChanged: function(up) {
			},

			UploadProgress: function(up, file) {
				file.size = 0;
				file.percent = 0;
				file.status = 2;
			},

			FilesAdded: function(up, files) {
			},

			FilesRemoved: function(up, files) {
			},

			FileUploaded: function(up, file, info) {
				<%if (null != isNeedAddRow || "y".equalsIgnoreCase(isNeedAddRow)) {%>
					var res = info.response.split("|");
					if(res.length > 0){
						if(res[0].indexOf("success") > -1){
							var intFileSize = res[2];
							var idx = intFileSize.indexOf("</pre>");
							if(idx == -1){
								idx = intFileSize.indexOf("</PRE>");
							}
							if(idx > -1){
								intFileSize = intFileSize.substring(0,idx);
							}
							file.size = intFileSize;
							file.percent = 100;
							file.status = 5;
							addRow('<%=pkReleaseFileB%>',file.name,intFileSize,res[1]);
						}else{
							file.status = 4;
							var strErrMsg = res[1];
							var idx = strErrMsg.indexOf("</pre>");
							if(idx == -1){
								idx = strErrMsg.indexOf("</PRE>");
							}
							if(idx > -1){
								strErrMsg = strErrMsg.substring(0,idx);
							}
							if(strErrMsg == "FILE_NAME_TOO_LONG"){
								alert("文件名过长导致上传失败！");
							}else {
								alert(strErrMsg);
							}
						}
					}
				<%}else{%>
						window.opener.refreshPage();
				 <%}%>
			},

			ChunkUploaded: function(up, file, info) {
			},

			Error: function(up, args) {
				alert(args.message);
			}
		}
	});
	if(ispic && ispic == 'Y'){
		$("#uploader_container").before("<span style='color:red'>仅限jpg和png图片格式(不大于500kb)</span>");
	}
	jQuery('#uploader').pluploadQueue().trigger('Refresh');
	
});

function refreshParent(){
	<%if (null == isNeedAddRow || "n".equalsIgnoreCase(isNeedAddRow)) {%>
	window.opener.refreshPage();
	<%}%>
}

function addRow(pkReleaseFileB,replyFileName,replyFileSize,replyFilePath){
	window.opener.addFileRow(pkReleaseFileB,replyFileName,replyFileSize,replyFilePath, "<%=id%>");
}

//文件客户端签名
function getSignMsg(filePath){
	<%
	 if (Constants.CA_FACTORY_INFOSEC.equals(strCaFactory)) {
	%>
		filePath = filePath.replace(/\//g,"\\");
	<%
		}
	%>
	return SignFile(filePath,"<%=userCode%>");
}
</script>
</body>
</html>